package wfmanage.action;

import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.util.MyLog;

import edu.wfmanage.models.Claim;
import edu.wfmanage.models.User;
/**
Author: Satya Deepthi Bhagi
**/
public class financeRequest extends ActionSupport {
	
	private static final long serialVersionUID = 1L;
	private int RequestId;
	private int LTALimit;
	private String username;
	private String userid;
	private int Fare;
	private int ApprovedAmount;
	Claim claim=new Claim();
	public String execute() throws Exception {
		Map<String, Object> session = ActionContext.getContext().getSession();
		User user = (User) session.get("user");
		if (user == null) {
			user = new User();
		}		
		MyLog.log("\nRequest id getting from jsp is"+RequestId);
		System.out.println("\nRequest id getting from jsp is"+RequestId);
		claim = Claim.findonetoapprove("select * from request where req_id= " + RequestId);
		username=user.getUsername();
		MyLog.log("user id is:"+user.getUserid());
		System.out.println("user id is:"+user.getUserid());
		String uid=Claim.getUserId("select user_id from request where req_id="+RequestId);
		LTALimit=Claim.getLTALimit("select LTA_Limit from employee where user_id= '" + uid+"'");
		MyLog.log("LTA limit is"+LTALimit);
		System.out.println("LTA limit is"+LTALimit);
		if(claim.getFare()<LTALimit){
			claim.setApprovedAmount(claim.getFare());
			
		}
		if(claim.getFare()>=LTALimit){
			claim.setApprovedAmount(LTALimit);
		}
		return "financesuccess";
	}

	public int getFare() {
		return Fare;
	}

	public void setFare(int fare) {
		Fare = fare;
	}

	public int getApprovedAmount() {
		return ApprovedAmount;
	}

	public void setApprovedAmount(int approvedAmount) {
		ApprovedAmount = approvedAmount;
	}

	public String getUserid() {
		return userid;
	}

	public void setUserid(String userid) {
		this.userid = userid;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public Claim getClaim() {
		return claim;
	}

	public void setClaim(Claim claim) {
		this.claim = claim;
	}

	public int getRequestId() {
		return RequestId;
	}

	public void setRequestId(int requestId) {
		RequestId = requestId;
	}

	public int getLTALimit() {
		return LTALimit;
	}

	public void setLTALimit(int lTALimit) {
		LTALimit = lTALimit;
	}

	

	
}
